//
//  YYJLNewShopController.m
//  YuanyangJinlou
//
//  Created by mac004 on 2017/1/6.
//  Copyright © 2017年 suli19910309@qq.com. All rights reserved.
//

#import "YYJLNewShopController.h"
#import "YYJLNewShopShowCell.h"
#import "YYJLNewShopDetailController.h"
#import "CarmaerView.h"
#import "TZImagePickerController.h"
@interface YYJLNewShopController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,CarmaerViewdelege,TZImagePickerControllerDelegate,UINavigationControllerDelegate>
{
    UICollectionView*_collectionView;
    UIView * bluryView;//覆盖层
    CarmaerView * carmerView;
    NSMutableArray * picArr;//图片数组
}

@end

@implementation YYJLNewShopController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setTitleView:@"新店加盟"];
    [self setBackItem];
    [self setrightItem];
    [self creatUI];
    
    picArr =[[NSMutableArray alloc]init];

}
-(void)right{
    
    [self.view bringSubviewToFront:bluryView];
    carmerView =[[CarmaerView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT-230*PER_HEIGHT, SCREEN_WIDTH, 230*PER_HEIGHT)];
    carmerView.backgroundColor=[UIColor clearColor];
    carmerView.delege=self;
    [bluryView addSubview:carmerView];
}
-(void)setrightItem{
    UIImage * img =[UIImage imageNamed:@"ico_tianjia1"];
    UIImageView * imgView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, img.size.width*PER_WIDTH, img.size.height*PER_WIDTH)];
    imgView.image=img;
    [self setRightBarItems:imgView];
}

-(void)creatUI{
    UICollectionViewFlowLayout*layout=[[UICollectionViewFlowLayout alloc]init];
    _collectionView =[[UICollectionView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT) collectionViewLayout:layout];
    _collectionView.backgroundColor=UIColorFromHex(0xf7f7f7);
    _collectionView.dataSource=self;
    _collectionView.delegate=self;
    [self.view addSubview:_collectionView];
    [_collectionView registerClass:[YYJLNewShopShowCell class] forCellWithReuseIdentifier:@"cell"];
    bluryView =[[UIView alloc]initWithFrame:self.view.bounds];
    bluryView.backgroundColor=[UIColorFromHex(0x000000) colorWithAlphaComponent:.4];
    [self.view addSubview:bluryView];
    [self.view sendSubviewToBack:bluryView];
}
#pragma mark--collection
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 4;
}
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    YYJLNewShopShowCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.backgroundColor=UIColorFromHex(0xffffff);
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    YYJLNewShopDetailController*detail=[[YYJLNewShopDetailController alloc]init];
    [self.navigationController pushViewController:detail animated:YES];
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(171*PER_WIDTH, 159*PER_HEIGHT);
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(10*PER_HEIGHT, 12*PER_WIDTH, 10*PER_HEIGHT, 10*PER_WIDTH);
}
#pragma mark--第三方相册协议
-(void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets infos:(NSArray<NSDictionary *> *)infos{
    NSLog(@"info==%@",infos);
    if (photos.count>0) {
        
        for (UIImage *img in photos) {
          //  UIImage *originImg = [UIImage imageWithData:[self onGetPictureForIMG:img]];
            //[picArr addObject:originImg];
            [picArr addObject:img];
            
        }
        //少于五张图片或者多余九张图片 预处理
        
        
        //直接上传
        [self.navigationController dismissViewControllerAnimated:YES completion:^{
         
            
        }];
        
    }
}

#pragma mark--carmerdelegete
-(void)choosePhoto{
    
 TZImagePickerController*pick=[[TZImagePickerController alloc]initWithMaxImagesCount:15 delegate:self];
        [pick setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos,NSArray *assets,BOOL isSelectOriginalPhoto) {
            
        }];
    
        [self.navigationController presentViewController:pick animated:YES completion:nil];
    


}
-(void)chooseCarmer{
    if (![UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) {
        NSLog(@"该手机不能拍照");
        return;
    }
    
    TZImagePickerController*pick=[[TZImagePickerController alloc]initWithMaxImagesCount:15 delegate:self];
    [pick setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos,NSArray *assets,BOOL isSelectOriginalPhoto) {
        
    }];
    
    [self.navigationController presentViewController:pick animated:YES completion:nil];
    

}
-(void)cancel{
    [carmerView removeFromSuperview];
    [self.view sendSubviewToBack:bluryView];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
